package com.yogis;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.yogis.entity.User;
import com.yogis.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/dbsplit")
@SpringBootApplication
public class DbSplitApplication {

    @Autowired
    private UserService userService;

    public static void main(String[] args) {
        SpringApplication.run(DbSplitApplication.class, args);
    }

    @GetMapping("/select")
    public List<User> select() {
        return userService.list(new QueryWrapper<User>().orderByDesc("name"));
    }

    @GetMapping("/count")
    public Integer count(){
        return userService.count();
    }

    @GetMapping("/selectOne")
    public User select(@RequestParam("id") Integer id) {
        return userService.getOne(new QueryWrapper<User>().lambda().eq(User::getId, id).last("limit 1"));
    }

    @PostMapping("/insert")
    public Boolean insert(@RequestBody User user) {
        return userService.save(user);
    }
}
